import React, { useEffect } from 'react'
import { useNavigate, useLocation } from "react-router-dom"
const useAuth = () => {
  const navigate = useNavigate()
  const { pathname } = useLocation()
  useEffect(() => {
    const token = localStorage.getItem("token")
    if (!token && pathname !== "/login") {
      navigate("/login")
    }
  }, [pathname, navigate])
}

export default useAuth
